package com.example.mqdemo;

import com.example.mqdemo.direct.DirectProducer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class MqDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(MqDemoApplication.class, args);
    }
    /*@Bean
    public CommandLineRunner run(PointToPointProducer producer) {
        return args -> {
            // 发送消息到队列
            producer.sendMessage("Hello, RabbitMQ!");
        };
    }*/
    //注意：WorkProducer是：roundRobinDispatch.WorkProducer;
    /*@Bean
    public CommandLineRunner run(WorkProducer producer){
        return args -> {
            //发送消息到work队列
            producer.sendMessage("这是发送到工作队列的消息");
        };
    }*/
    //注意：WorkProducer是：fairDispatch.WorkProducer;
    /*@Bean
    public CommandLineRunner run(WorkProducer producer){
        return args -> {
            //发送消息到work队列
            producer.sendMessage("这是发送到工作队列的消息");
        };
    }*/
    /*@Bean
    public CommandLineRunner run(SubscribeProducer producer){
        return args -> {
            //发送消息到subscribe队列
            producer.sendMessage("这是发送到subscribe队列的消息");
        };
    }*/
    @Bean
    public CommandLineRunner run(DirectProducer producer){
        return args -> {
            for (int i=1;i<=10;i++){
                if(i%3==0)producer.sendErrorMessage("这是发送到direct队列的error消息"+i);
                else producer.sendInfoMessage("这是发送到direct队列的info消息"+i);
            }
        };
    }
}
